import axios from 'axios'

// 进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
// 配置请求的根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

// 请求拦截
axios.interceptors.request.use(
  config => {
    NProgress.start()
    config.headers.Authorization = window.sessionStorage.getItem('token')
    return config
  },
  error => {
    NProgress.done()
    alert('请求超时，请稍后重试！')
    return Promise.reject(error)
  }
)

// 响应拦截
axios.interceptors.response.use(config => {
  NProgress.done()
  return config
})

export default axios
